package ;

/**
 * ...
 * @author tom
 */
class JBuffer {
	var b:haxe.io.Bytes;
	var bo:haxe.io.BytesOutput;
	var bi:haxe.io.BytesInput;
	public function new (b:haxe.io.Bytes) {
		this.b = b;
		bo = null;
		bi = null;
	}		
	public function array() {
		return b.getData();
	}
	public function arrayOffset() {
		return 0;
	}
	public function capacity() {
		return b.length;
	}
	public function clear() {
		var l = b.length;
		var bi = new haxe.io.BytesOutput();
		while(l-- > 0) {
			bi.writeByte(0);
		}
		b = bi.getBytes();
		return this;
	}
	public function flip() {
		var s = b.getData();
		var n = new haxe.io.BytesData();
		while(s.length > 0)
			n.push(s.pop());
		b = n;
		return this;
	}
	public function hasRemaining() {
		var by = this.bi.readAll();
		this.bi = new haxe.io.BytesInput(by);
		return by.length > 0;
	}
}